package com.hengxinguotong.zhihuichengjian.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.hengxinguotong.zhihuichengjian.ui.app.BaseFragment;

import java.util.List;

/**
 * Created by Administrator on 2016/5/23.
 */
public class DeviceListPagerAdapter extends FragmentPagerAdapter {
    List<BaseFragment> fragments ;
    String[] tags ;
    public DeviceListPagerAdapter(FragmentManager fm, List<BaseFragment> fragments) {
        super(fm);
        this.fragments = fragments;
        tags  = new String[fragments.size()];
    }


    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    public String getFragmentTag(int position) {
        return tags[position];
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Fragment fragment = (Fragment) super.instantiateItem(container, position);
        tags[position]  =  fragment.getTag();
        return fragment;
    }
}
